package routes

import (
	"github.com/zeromicro/go-zero/rest"
	"net/http"
)

func ServerRegis(server *rest.Server) {

	// 首页跳转到静态页面
	server.AddRoute(rest.Route{
		Method: http.MethodGet,
		Path:   "/",
		Handler: func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, "./static/index.html")
		},
	})

	// 静态文件
	server.AddRoute(rest.Route{
		Method:  http.MethodGet,
		Path:    "/static/*filepath",
		Handler: http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))).ServeHTTP,
	})
	// 个人中心页面路由
	server.AddRoute(rest.Route{
		Method: http.MethodGet,
		Path:   "/static/profile.html",
		Handler: func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, "./static/profile.html")
		},
	})
	// 游戏大厅和各游戏页面静态路由
	server.AddRoute(rest.Route{
		Method: http.MethodGet,
		Path:   "/static/game-lobby.html",
		Handler: func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, "./static/game-lobby.html")
		},
	})
	server.AddRoute(rest.Route{
		Method: http.MethodGet,
		Path:   "/static/snake.html",
		Handler: func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, "./static/snake.html")
		},
	})
	server.AddRoute(rest.Route{
		Method: http.MethodGet,
		Path:   "/static/gomoku.html",
		Handler: func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, "./static/gomoku.html")
		},
	})
	server.AddRoute(rest.Route{
		Method: http.MethodGet,
		Path:   "/static/tictactoe.html",
		Handler: func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, "./static/tictactoe.html")
		},
	})
	// 新增：common.js 静态路由
	server.AddRoute(rest.Route{
		Method: http.MethodGet,
		Path:   "/static/common.js",
		Handler: func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("Content-Type", "application/javascript")
			http.ServeFile(w, r, "./static/common.js")
		},
	})
}
